<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>添加和修改商城物品</title>
	<%@ include file="/view/common/tags.jsp"%>
</head>
<body>
	<div class="well well_p" >
		<sk:form method="post" cssClass="form-horizontal" action="${sysManagerV1}/pubgExchangeGoods/savePubgExchangeGoods" id="saveAndUpdateForm" target="_parent">
			<div class="form-group">
				<label class="col-xs-3 text-right">物品名称:</label>
				<div class="col-xs-5">
					<input type="text" class="form-control" name="goodsName" id="goodsName" value="${pubgExchangeGoods.goodsName }" maxlength = "20" placeholder="20个字符以内" onblur="checkGoodsNameBlur()">
					<input type="hidden" id="rowId" name="rowId" value="${pubgExchangeGoods.rowId }">
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-3 text-right">物品价格:</label>
				<div class="col-xs-5">
					<input type="text" class="form-control" name="goodsPrice" id="goodsPrice" value="${pubgExchangeGoods.goodsPrice }" maxlength="7" placeholder="">鸡蛋
				</div>
			</div>
			<div class="form-group" >
				<label class="col-xs-3 text-right">是否开启:</label>
				<div class="col-xs-7">
					<td colspan="2">
						<label><input name="openFlag" type="radio" checked="checked"  value="1"/>&nbsp;是</label>&nbsp;&nbsp;&nbsp;&nbsp;
						<label><input name="openFlag" type="radio"  value="0"/>&nbsp;否</label>
					</td>
				</div>
			</div>
			<input type="hidden" id="isReCommit" value="0">
		</sk:form>
	</div>
</body>
   <%@ include file="/view/common/footer.jsp"%>
   <script type="text/javascript">
       $(function(){
           var rowId = $('#rowId').val();
           if (rowId != null && rowId > 0) {
               $('#goodsName').attr("readonly", true);
		   }
       });
       //商城物品名是否存在，失去焦点事件
       function checkGoodsNameBlur() {
           var goodsName = $('#goodsName').val();
           var goodsPrice = $('#goodsPrice').val();
           var rowId = $('#rowId').val();
           if (rowId == null) {
               rowId = 0;
           }
           $.post(JSSYSMANAGERV1 + "/pubgExchangeGoods/checkGoodsName?rowId="+rowId+"&goodsName="+goodsName,function(result){
               if (result != null) {
                   if (result.code == '-1') {
                       layer.msg("商品验证出错！");
                       return;
                   } else if (result.code == '-2') {
                       layer.msg(result.message);
                       return;
                   }
               }
           });
       }
    //添加修改商城物品
	function add(){
		var rowId = $('#rowId').val();
	    var goodsName = $('#goodsName').val();
	    if (goodsName == null || goodsName == '') {
	        layer.msg("商城物品名称不能为空!");
	        return;
	    }
	    if (goodsName.length > 20) {
            layer.msg("商城物品名称最多输入20个字符!");
            return;
	    }
	    checkGoodsName();//商城物品名是否存在
	}

	//提交时验证
	//商城物品名是否存在
	function checkGoodsName() {
        var goodsName = $('#goodsName').val();
        var goodsPrice = $('#goodsPrice').val();
        var rowId = $('#rowId').val();
        if (rowId == null) {
            rowId = 0;
        }
		$.post(JSSYSMANAGERV1 + "/pubgExchangeGoods/checkGoodsName?rowId="+rowId+"&goodsName="+goodsName,function(result){
			if (result != null) {
				if (result.code == '-1') {
					layer.msg("商品验证出错！");
					return;
				} else if (result.code == '-2') {
					layer.msg(result.message);
					return;
				} else if (result.code == '0') {
                    if (goodsPrice == null || goodsPrice == '') {
                        layer.msg("物品价格不能为空!");
                        return;
                    }
                    if (!CheckUtil.isInt(goodsPrice, "+") && !CheckUtil.isFloat(goodsPrice, "+")) {
                        layer.msg("物品价格只能为正数!");
                        return;
                    }
                    if (parseFloat(goodsPrice) <= 0 || parseFloat(goodsPrice) >1000000) {
                        layer.msg("物品价格0到100万之间!");
                        return;
                    }
                    if ($("#isReCommit").val() == 0) {
                        $("#isReCommit").val(1);
                        $("#saveAndUpdateForm").submit();
                    }
				}
			}
		});
	}
   </script>
</html>